package cn.lcsjsxy.yxz.day.Reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

//练习
public class Practice {
    public static void main(String[] args) throws Exception{

        //员工的登录功能:

        //构建方法对象
        Class empClass = Emp.class;
        Constructor declaredConstructor = empClass.getDeclaredConstructor();
        //构建对象
        Object emp = declaredConstructor.newInstance();

        //获取对象属性
        Field account = empClass.getField("account");
        Field password = empClass.getField("password");

        //属性赋值
       account.set(emp, "yang");
       password.set(emp, "123456");

        //登录
        Method login = empClass.getMethod("login");
        //调用
        Object result = login.invoke(emp);
        //输出
        System.out.println(result);

    }
}
//员工
class Emp {
    public String account;
    public String password;

    //判断
    public boolean login(){
        if ("yang".equals(account) && "123456".equals(password)){
            return true;
        } else {
            return false;
        }
    }
}